local fulun = fk.CreateSkill {
    name = "xiaobai__fulun"
  }
  
  Fk:loadTranslationTable {
    ["xiaobai__fulun"] = "富论",
    [":xiaobai__fulun"] = "出牌阶段限一次，你可以展示所有手牌，然后将其中点数最小的牌当【无中生有】使用，"..
      "若你因此获得的牌中有点数比底牌小的，你可以重复此流程。",
    ["#xiaobai__fulun"] = "富论：你可以展示所有手牌，将点数最小的牌当【无中生有】使用",
    ["#xiaobai__fulun_repeat"] = "富论：你可以重复此流程",
  }
  
  fulun:addEffect("active", {
    prompt = "#xiaobai__fulun",
    anim_type = "offensive",
    pattern = "ex_nihilo",
    max_turn_use_time = 1,
    card_num=0,
    target_num=0,
    can_use = function(self, player, card)
      return player:usedSkillTimes(self.name,Player.HistoryPhase) < 1
    end,
    on_use = function(self, room, effect)
      local player=effect.from
      local cards=player:getCardIds("h")
      player:showCards(cards)
      local min_card
      for _,cid in ipairs(cards) do
        local card=Fk:getCardById(cid)
        if not min_card or card.number < min_card.number then
          min_card=card
        end
      end
      room:useVirtualCard("ex_nihilo",{min_card.id}, player,player, fulun.name)

    end

  })


  fulun:addEffect(fk.CardUseFinished,{
    anim_type ="support",
    can_trigger = function(self, event, target, player, data)
      if not player:hasSkill(fulun.name) or player.dead then return false end
     
      if data.card.name == "ex_nihilo" and table.contains(data.card.skillNames,fulun.name) then
        local room=player.room
        local use_event = room.logic:getCurrentEvent()
        local mincard=data.card.subcards[1]
        local min_number=Fk:getCardById(mincard).number
        local cards={}
        room.logic:getEventsOfScope(GameEvent.MoveCards, 99, function(e)
          if e.id>use_event.id then
             
          for _, move in ipairs(e.data) do
            if move.toArea == Card.PlayerHand and move.skillName == "ex_nihilo_skill" and move.to==player then
              for _, info in ipairs(move.moveInfo) do
                table.insertIfNeed(cards,info.cardId)
              end
            end
          end
          end
        end, Player.HistoryTurn)
        local new_min_number=min_number
        for _,cid in ipairs(cards) do
          local card=Fk:getCardById(cid)
          if card.number < new_min_number then
            new_min_number=card.number
            mincard=cid
          end
        end
        if new_min_number < min_number then
          event:setCostData(self,mincard)
          return true
        end
      end
    end,
    on_use = function(self, event, target, player, data)
      local room=player.room
      local mincard=event:getCostData(self)
      room:useVirtualCard("ex_nihilo",{mincard}, player,player, fulun.name)
    end,
  })
  
  return fulun